/* Tables1.do (STATA)
	Tables and figures for variance decomposition of euro-area debt.
	by Ralph Koijen & Motohiro Yogo */

#delimit ;
clear all;
set more off;
set type double;
set scheme s1mono;

cap log close;
log using Tables1, replace;

/* Define local and global variables */

local path = "../../figures";

local clist = "^(GRC|ITA|PRT)$";


/* Step 1: Variance decomposition */

/* Load data */

u year counter_euro Name type Dyield*
	if regexm(counter_euro,"`clist'") & type==2
	using Decomposition0, clear;

/* Loop by country */

levelsof Name;

foreach i in `r(levels)' {;

	/* Estimate variance decomposition */

	qui forval j = 1/9 {;
		reg Dyield`j' Dyield if Name=="`i'", robust;

		eststo Dyield`j';
	};

	/* Table: Variance decomposition */

	esttab, b(%8.2f) se(%8.2f) plain
		keep(Dyield);

	eststo clear;
};


/* Step 2: Plot figures */

/* Report in percent */

qui foreach var of varlist Dyield* {;
	replace `var' = 100*`var';
};

/* Specify panel labels */

replace Name = "A. Greece" if Name=="Greece";
replace Name = "B. Italy" if Name=="Italy";
replace Name = "C. Portugal" if Name=="Portugal";

/* Label variables */

label var Dyield	"Change in yield";
label var Dyield2	"Macro variables";
label var Dyield9	"Latent demand";

/* Figure: Change in yield by country */

twoway line Dyield Dyield2 Dyield9 year
	if counter_euro=="GRC",
	by(Name, legend(pos(12) at(2)) note(""))
	lc(black gs4 gs8)
	lp(solid dash longdash)
	ylabel(-20(10)20, angle(0))
	tlabel(2004(4)2020)
	ytitle("Change in yield (%)")
	legend(col(1) order(1 - "due to" 2 3))
	xsize(6) ysize(3)
	saving(GRC, replace);

twoway line Dyield Dyield2 Dyield9 year
	if inlist(counter_euro,"ITA","PRT"),
	by(Name, legend(off) note(""))
	lc(black gs4 gs8)
	lp(solid dash longdash)
	ylabel(-10(5)10, angle(0))
	tlabel(2004(4)2020)
	ytitle("Change in yield (%)")
	xsize(6) ysize(3)
	saving(ITA, replace);

/* Output figure */

graph combine GRC.gph ITA.gph,
    rows(2) altshrink xsize(6) ysize(6);

graph export "`path'/Euro.eps", replace;

rm GRC.gph;
rm ITA.gph;

log close;
